package com.xiaomi.shwx.controller.material;

import com.xiaomi.shwx.common.result.Result;
import com.xiaomi.shwx.entity.dto.MaterialsDTO;
import com.xiaomi.shwx.entity.pojo.Material;
import com.xiaomi.shwx.service.MaterialService;
import com.xiaomi.shwx.service.WorkOrderService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Slf4j
@RequestMapping("/api/material")
public class MaterialController {

    @Resource
    private WorkOrderService workOrderService;

    @Resource
    private MaterialService materialService;

    /**
     * 申请维修材料
     * @param materialsDTO
     * @return
     */
    @PostMapping("/application")
    @ApiOperation("申请维修材料")
    public Result applyMaterials(@RequestBody MaterialsDTO materialsDTO){
        log.info("工程师申请维修材料:{}", materialsDTO);
        workOrderService.applyMaterials(materialsDTO);
        return Result.ok();
    }


    /**
     *
     * @return 获取所有物料信息
     */
    @GetMapping("/all")
    public Result<List<Material>> getAllMaterial() {
        log.info("获取所有物料信息:{}");
        return Result.ok(materialService.getAllMaterial());
    }

}
